import Foundation
import Combine

class ReminderSettings: ObservableObject {
    @Published var interval: Int = 30 // 默认提醒间隔：30分钟
    @Published var isSoundEnabled: Bool = true
    @Published var isVibrationEnabled: Bool = true
    @Published var startTime: Date = Calendar.current.date(bySettingHour: 8, minute: 0, second: 0, of: Date()) ?? Date()
    @Published var endTime: Date = Calendar.current.date(bySettingHour: 22, minute: 0, second: 0, of: Date()) ?? Date()
    
    // 保存设置到UserDefaults
    func saveSettings() {
        let defaults = UserDefaults.standard
        defaults.set(interval, forKey: "reminderInterval")
        defaults.set(isSoundEnabled, forKey: "isSoundEnabled")
        defaults.set(isVibrationEnabled, forKey: "isVibrationEnabled")
        defaults.set(startTime, forKey: "startTime")
        defaults.set(endTime, forKey: "endTime")
    }
    
    // 从UserDefaults加载设置
    func loadSettings() {
        let defaults = UserDefaults.standard
        interval = defaults.integer(forKey: "reminderInterval")
        isSoundEnabled = defaults.bool(forKey: "isSoundEnabled")
        isVibrationEnabled = defaults.bool(forKey: "isVibrationEnabled")
        
        if let start = defaults.object(forKey: "startTime") as? Date {
            startTime = start
        }
        
        if let end = defaults.object(forKey: "endTime") as? Date {
            endTime = end
        }
    }
} 